<!--
 * @Descripttion: 
 * @Author: zhanyi
 * @Date: 2021-10-20 10:26:08
 * @FilePath: \wczd-mobile\src\pages\home\home.vue
-->
<template>
  <div class="home">
    <div class="login-logo">
      <image src="@/static/wczd/wczd-logo.png" mode=""></image>
      <div class="message">
        <div>
          <image src="@/static/wczd/messageHL.png"></image>
          <text @click="openMsgDetail(msg.id)" class="msg-title" v-if="msg.title">{{msg.title+':'+msg.msg}}</text>
        </div>
        <image src="@/static/wczd/more.png"></image>
      </div>
    </div>
    <div class="main-cont">
      <div class="title">主要功能</div>
      <div class="major">
        <div v-hasPermi="item.perm" class="major-item" v-for="(item,index) in quickitems" :key="index" :style="{ background: item.colorBK,color:item.color }" @click="toPage(item)">
          <div class="img">
            <image :src="item.imgUrl"></image>
          </div>
          <div class="label">
            {{item.name}}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import scanBox from "../component/scan-box/scan-box.vue";
import { msgListToMine } from "@/api/user";
export default {
  name: 'home',
  components: { scanBox },
  data () {
    return {
      msg: {},
      quickitems: [
        { name: '安全检查', colorBK: '#e7e6e5', color: '#896C4C', imgUrl: '/static/wczd/inspect.png', toPage: '/pages/safeCheck/safeCheck', perm: ['business:securityCheck:list'] },
        { name: '任务管理', colorBK: '#d9efeb', color: '#00C588', imgUrl: '/static/wczd/note.png', toPage: '/pages/task/task', perm: ['inspection:whInspectionTask:list'] },
        { name: '隐患随手拍', colorBK: '#d0eaf2', color: '#4ec3e0', imgUrl: '/static/wczd/camera.png', toPage: '/pages/component/hidden-danger/hiddenDanger', perm: null },
        { name: '隐患治理', colorBK: '#d9ebf4', color: '#019fdf', imgUrl: '/static/wczd/risk.png', toPage: '/pages/danger/danger', perm: ['inspection:whDangerRegister:list'] },
        { name: '作业许可管理', colorBK: '#f3e5e2', color: '#FF6330', imgUrl: '/static/wczd/work.png', toPage: '/pages/archives/archives', perm: ['business:jobManagerInfo:list'] },
        { name: '统计分析', colorBK: '#d9e5ec', color: '#036792', imgUrl: '/static/wczd/analyse.png', toPage: '/pages/analysis/analysis', perm: null },
        { name: '积分排名', colorBK: '#fff3dc', color: '#ffc655', imgUrl: '/static/wczd/rank.png', toPage: '/pages/integral/integral', perm: null },
      ]
    }
  },
  computed: {},
  mounted () {
    this.msgListToMine()

  },
  watch: {},
  methods: {
    //获取信息
    msgListToMine () {
      msgListToMine({ pageNum: 1, pageSize: 1 }).then(res => {
        if (res.rows.length > 0) {
          this.msg = res.rows[0]
        }
      })
    },
    //打开信息详情
    openMsgDetail (id) {
      uni.navigateTo({
        url: `/pages/my-info/my-message`
      })
    },
    toPage (item) {
      if (item.name === '隐患治理' || item.name === '任务管理') {
        uni.switchTab({
          url: item.toPage
        })
      } else {
        uni.navigateTo({
          url: item.toPage
        });
      }
    }
  },
}
</script>

<style scoped lang="scss">
.home {
  position: relative;
  height: 100%;
  background: url("@/static/wczd/login-bk.png") no-repeat;
  background-size: 100% 30%;
  background-color: #f1f4f6;
  .login-logo {
    padding-top: 40upx;
    padding-bottom: 40upx;
    height: 30%;
    width: 100%;
    display: flex;
    align-items: center;
    flex-direction: column;
    justify-content: space-between;
    .message {
      padding: 0 30upx;
      height: 90upx;
      line-height: 90upx;
      background-color: rgba(255, 255, 255, 0.5);
      width: 100%;
      color: #009fdf;
      font-weight: bold;
      display: flex;
      align-items: center;
      justify-content: space-between;
      div {
        display: flex;
        align-items: center;
      }
      image {
        width: 45upx;
        height: 50upx;
        margin-right: 10upx;
      }
    }
    > image {
      width: 200upx;
      height: 200upx;
    }
  }
  .msg-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 570upx;
  }
  .main-cont {
    height: 70%;
    overflow: auto;
    .title {
      font-size: 35upx;
      font-weight: bold;
      text-align: center;
      width: 320upx;
      margin: 20upx auto;
      background: url("@/static/wczd/title-bk.png") no-repeat;
      background-size: 100% 100%;
    }
    .major {
      display: flex;
      flex-wrap: wrap;
      padding: 0 10upx;
      .major-item {
        width: calc(50% - 20upx);
        height: 248upx;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        background-color: red;
        margin: 10upx;
        border-radius: 10px;
        font-weight: bold;
        .img {
          image {
            width: 110upx;
            height: 110upx;
          }
        }
      }
    }
  }
}
</style>
